!function(a, c) {
    function h() {
        var c = f.getBoundingClientRect().width;
        c / i > 540 && (c = 540 * i);
        var h = c / 10;
        f.style.fontSize = h + "px",
            g.rem = a.rem = h
    }
    var d, e = a.document,
        f = e.documentElement,
        v = e.querySelector('meta[name=viewport]'),
        b = e.querySelector('meta[name=flexible]'),
        i = 0,
        w = 0,
        g = c.flexible || (c.flexible = {});
    if (v) {
        console.warn("将根据已有的meta标签来设置缩放比例");
        var l = v.getAttribute("content").match(/initial\-scale=([\d\.]+)/);
        l && (w = parseFloat(l[1]), i = parseInt(1 / w))
    } else if (b) {
        var m = b.getAttribute("content");
        if (m) {
            var n = m.match(/initial\-dpr=([\d\.]+)/),
                o = m.match(/maximum\-dpr=([\d\.]+)/);
            n && (i = parseFloat(n[1]), w = parseFloat((1 / i).toFixed(2))),
            o && (i = parseFloat(o[1]), w = parseFloat((1 / i).toFixed(2)))
        }
    }
    if (!i && !w) {
        var p = a.navigator.userAgent,
            q = ( !! p.match(/android/gi), !!p.match(/iphone/gi)),
            r = q && !!p.match(/OS 9_3/),
            s = a.devicePixelRatio;
        i = q && !r ? s >= 3 && (!i || i >= 3) ? 3 : s >= 2 && (!i || i >= 2) ? 2 : 1 : 1,
            w = 1 / i
    }
    if (f.setAttribute("data-dpr", i), !v) if (v = e.createElement("meta"), v.setAttribute("name", "viewport"), v.setAttribute("content", "initial-scale=" + w + ", maximum-scale=" + w + ", minimum-scale=" + w + ", user-scalable=no"), f.firstElementChild) f.firstElementChild.appendChild(v);
    else {
        var t = e.createElement("div");
        t.appendChild(v),
            e.write(t.innerHTML)
    }
    a.addEventListener("resize",
        function() {
            clearTimeout(d),
                d = setTimeout(h, 300)
        },
        !1),
        a.addEventListener("pageshow",
            function(a) {
                a.persisted && (clearTimeout(d), d = setTimeout(h, 300))
            },
            !1),
        "complete" === e.readyState ? e.body.style.fontSize = 12 * i + "px": e.addEventListener("DOMContentLoaded",
                function() {
                    e.body.style.fontSize = 12 * i + "px"
                },
                !1),
        h(),
        g.dpr = a.dpr = i,
        g.refreshRem = h,
        g.rem2px = function(a) {
            var c = parseFloat(a) * this.rem;
            return "string" == typeof a && a.match(/rem$/) && (c += "px"),
                c
        },
        g.px2rem = function(a) {
            var c = parseFloat(a) / this.rem;
            return "string" == typeof a && a.match(/px$/) && (c += "rem"),
                c
        }
} (window, window.lib || (window.lib = {}));
